package Bacterias;

import java.util.List;

import Enums.AnimationType;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.Log;
import android.view.MotionEvent;

import com.game.ThauanFramework.BitmapStorage;
import com.game.ThauanFramework.GameObject;
import com.game.ThauanFramework.Util;
import com.game.ThauanFramework.SoundManager;
import com.game.ThauanFramework.Sprite;
import com.game.ThauanFramework.SpriteAnimationData;
import com.thauanLopes.bacterium.GameSceneView;
import com.thauanLopes.bacterium.GameManages.GameManager;
import com.thauanLopes.bacterium.GameManages.GameManagerFactory;
import com.thauanLopes.bacterium.GameManages.ScoreManager;
import com.thauanLopes.smagasmaga.R;

public class PostDeathEffect extends GameObject {

	private final String TAG = "Pos Mortem Sprite";

	private List<GameObject> cemetery;
	private List<GameObject> gameObjects;
	
	private boolean alive = true;
	
	public int opacity = 100;

	private int centerX;
	private int centerY;

	private float lifeTime = 1f;

	private Sprite sprite;
	private Rect destRect;

	private Bitmap bitmap;

	public PostDeathEffect(List<GameObject> gameObjects, List<GameObject> cemetery, int centerX, int centerY) {

		this.cemetery = cemetery;
		this.gameObjects = gameObjects;

		this.centerX = centerX;
		this.centerY = centerY;
		
		this.bitmap = BitmapStorage.getInstance().getBitmap(
				R.drawable.monstro_efeito_pos_morte);
		this.sprite = new Sprite();
		this.sprite.Start(new SpriteAnimationData(this.bitmap, 1, 2,
				AnimationType.LOOP));

		this.destRect = new Rect(this.centerX - bitmap.getWidth()/2,
				this.centerY - bitmap.getHeight()/2,
				this.centerX + bitmap.getWidth() /2,
				this.centerY + bitmap.getHeight()/2);
		
		DeathOpaticyRunnable dor = new DeathOpaticyRunnable(this, this.lifeTime);
		Thread thread = new Thread(dor);
		thread.start();
		gameObjects.add(this);
	}

	@Override
	public void Update(double deltaTime) {

	}

	@Override
	public void Draw(Canvas canvas) {
		if (alive) {
			this.sprite.setOpacity(this.opacity);
			this.sprite.Draw(canvas, this.destRect);
		}
	}

	@Override
	public void Die() {
		this.cemetery.add(this);
		this.alive = false;
	}

	@Override
	public void Destroy() {
		gameObjects.remove(this);
	}

	@Override
	public boolean onTouch(MotionEvent event) {

	return false;
		
	} 
}
